package com.iflytek.ci.qams.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.iflytek.ci.cums.service.AccountService;
import com.iflytek.ci.qams.dto.CommentAction;
import com.iflytek.ci.qams.service.CommentService;
import com.iflytek.ci.qams.service.IssueService;
import com.iflytek.ci.qams.service.TypeService;
import com.iflytek.framework.pagination.PaginationCriteria;
import com.iflytek.framework.pagination.PaginationResult;

@Controller
@RequestMapping(value="issue/**")
public class CommentController {
    @Autowired
	CommentService commentService;
    
    @Autowired
    TypeService typeService;
 
    @Autowired
    IssueService issueService;
    @Autowired
    AccountService accountService;
    
    /*
     * add a new comment
     * @param issue_id,model,u_id
     * @return addComment
     */
    @RequestMapping(value="/addComment",method = RequestMethod.POST)
    public String add_new_comment(Model model,long issue_id,long u_id){
    	Date date=new Date();
    	model.addAttribute("u_id", u_id);
    	model.addAttribute("u_name", accountService.fromId(u_id));
    	model.addAttribute("issue", issue_id);
    	model.addAttribute("created", date);
    	model.addAttribute("issue_label", 1);
		return "issue/addComment";
    }
    
    @RequestMapping(value="/getComment",method = RequestMethod.GET)
    public PaginationResult<CommentAction> get_commentByIssue_id(PaginationCriteria criteria,long issue_id){
    	return commentService.page_commentaction_by_issuekey(issue_id, criteria);
    }
}
